package com.fcml.pattern.strategy;

/**
 * 客户端调用
 * 这样设计的好处是，客户不再依赖于具体的收费策略，依赖于抽象永远是正确的。
 */
public class App {
    private Double totalAmount = 0D;            //客户消费的总额
    private Double amount = 0D;                 //客户单次消费金额
    private CountPrice countPrice = null;       //抽象的计价策略，实际上对应每个客户都有一个计算价格的策略

    //客户购买商品，就会增加它的总额
    private void buy(Double amount) {
        this.amount = amount;
        totalAmount += amount;

        if (totalAmount > 30000) {              //30000则改为黄金会员计算方式
            countPrice = new GoldVip();
        } else if (totalAmount > 20000) {       //类似
            countPrice = new SuperVip();
        } else if (totalAmount > 10000) {       //类似
            countPrice = new Vip();
        } else
            countPrice = new Normal();
    }

    //计算客户最终要付的钱
    private Double calLastAmount() {
        return countPrice.countPrice(amount);
    }


    public static void main(String[] args) {
        App app = new App();

        app.buy(5000D);
        System.out.println("用户实际付款：" + app.calLastAmount());

        app.buy(12000D);
        System.out.println("用户实际付款：" + app.calLastAmount());

        app.buy(12000D);
        System.out.println("用户实际付款：" + app.calLastAmount());

        app.buy(12000D);
        System.out.println("用户实际付款：" + app.calLastAmount());
    }
}